package com.wc.AlgoOJ.LQ1384T;

import java.util.Scanner;

/**
 * @Author congege
 * @Description 斐波那契与7
 * http://43.138.190.70:8888/p/LQ1384T
 * @Date Created in 2023/12/13-22:03
 */
public class Main {
    public static void main(String[] args) {
        int[] array = new int[100];
        int[] pre = new int[100];
        array[1] = 1;
        array[2] = 1;
        // 确定一轮循环的范围
        int size = 0;
        for (int i = 3; i <= 100; i++) {
            array[i] = (array[i - 1] + array[i - 2]) % 10;
            // 前缀和,表示每一轮循环的位置前面有多少个个位数是7的
            if (array[i] == 7) {
                pre[i] = pre[i - 1] + 1;
            } else {
                pre[i] = pre[i - 1];
            }
            if (array[i - 1] == 0 && array[i] == 1) {
                size = i - 1;
                break;
            }
        }
        // 取出一轮循环7的个数
        int oneCycle7 = pre[size];
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        while (n-- > 0) {
            long num = sc.nextLong();
            // 看有多少个循环
            long cycle = num / size;
            // 减去那几轮循环
            num -= cycle * size;
            long ans = cycle * oneCycle7 + pre[(int) num];
            System.out.println(ans);
        }
        //26960268160
    }
}
